﻿using System;
using Tree;

namespace calculator
{
    class Calculator
    {
        // const int maxBuf = 100;

        static void Main(string[] args)
        {
            Tables.StringTable strtable = new Tables.StringTable();
            strtable.ForceAdd("One");
            strtable.ForceAdd("Two");
            strtable.ForceAdd("Three");

            int id = strtable.Find("One");
            Console.WriteLine("One at {0}", id);
            id = strtable.Find("Two");
            Console.WriteLine("Two at {0}", id);
            id = strtable.Find("Three");
            Console.WriteLine("Three at {0}", id);
            id = strtable.Find("Minus one");
            Console.WriteLine("Minus one at {0}", id);
            Console.WriteLine("String 0 is {0}", strtable.GetString(0));
            Console.WriteLine("String 1 is {0}", strtable.GetString(1));
            Console.WriteLine("String 2 is {0}", strtable.GetString(2));

            // = (20.0+ (-10.0)) * 0.1
            Node n1 = new NumNode(20.0);
            Node n2 = new NumNode(-10.0);
            Node n3 = new AddNode(n1, n2);
            Node n4 = new NumNode(0.1);
            Node n5 = new MultNode(n3, n4);
            Console.WriteLine("Calculating tree...");
            // tell root to calc itself
            double x = n5.Result;
            Console.WriteLine(x);
            n5.Dispose();


            //char[] buf = new char[maxBuf];
            string input;
            Status status;
            SymbolTable symtab = new SymbolTable(127);
            FunctionTable funtab = new FunctionTable(symtab);
            Store store = new Store(127, symtab);
            do
            {
                Console.Write("> ");
                input = Console.ReadLine();
                // buf = input.ToCharArray();
                Scanner scanner = new Scanner(input);
                Parser parser = new Parser(scanner, symtab, store, funtab);
                status = parser.Eval();
            }
            while (status != Status.Quit);
        }
    }
}
